package cc.linker.steplink.crm.merchanth5.controller.acs;

import cc.linker.steplink.crm.commons.model.PcUserInfo;
import cc.linker.steplink.crm.merchanth5.commons.UserInfoUtil;
import cc.linker.steplink.crm.merchanth5.service.acs.MerchantSettingService;
import cc.linker.steplink.crm.response.GlobalException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/acs/merchant")
public class MerchantSettingController {
    @Autowired
    private MerchantSettingService merchantSettingService;
    @Autowired
    private UserInfoUtil userInfoUtil;

    @RequestMapping("/looksetting")
    public Object lookSetting(HttpServletRequest request){
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        return merchantSettingService.lookSetting(userinfo.getAdminId());
    }

    @RequestMapping("/setting")
    public void setting(@RequestBody Map param,HttpServletRequest request) throws GlobalException {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        Map<String,Object> map = new HashMap<>();
        if (null!=param){
            if (null!=param.get("promoterName")&&!"".equals(param.get("promoterName"))){
                if (param.get("promoterName").toString().length()<=6){
                    map.put("promoterName",param.get("promoterName"));
                }else {
                    throw GlobalException.build("请输入不大于6个字数的名称");
                }
            }else {
                throw GlobalException.build("请先填写完整信息信息");
            }
            if (null!=param.get("pageName")&&!"".equals(param.get("pageName"))){
                if (param.get("pageName").toString().length()<=6){
                    map.put("pageName",param.get("pageName"));
                }else {
                    throw GlobalException.build("请输入不大于6个字数的名称");
                }
            }else {
                throw GlobalException.build("请先填写完整信息");
            }
        }
        map.put("adminId",userinfo.getAdminId());
        merchantSettingService.setting(map);
    }
}